package com.example.xui.Main;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.xui.BlankFragment.BlankFragment;
import com.example.xui.BlankFragment.BlankFragment2;
import com.example.xui.Post_fragment.Popular_comment;
import com.example.xui.Post_fragment.annex_fragment;
import com.example.xui.Post_fragment.recommend_fragment;
import com.example.xui.R;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import java.lang.ref.PhantomReference;

public class FiveFragment extends Fragment {
    FragmentPagerItemAdapter adapter;
    recommend_fragment recommend_fragment=new recommend_fragment();
    com.example.xui.Post_fragment.annex_fragment annex_fragment=new annex_fragment();
    Popular_comment popular_comment=new Popular_comment();
    private String sno;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_five, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        sno=getActivity().getIntent().getStringExtra("sno");
        Bundle bundle=new Bundle();
        bundle.putString("sno",sno);
        recommend_fragment.setArguments(bundle);
        adapter = new FragmentPagerItemAdapter(
                getActivity().getSupportFragmentManager(), FragmentPagerItems.with(getContext())
                .add("推荐", recommend_fragment.getClass())
                .add("热门", popular_comment.getClass())
                .add("附近", annex_fragment.getClass())
                .create());

        ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
        viewPager.setAdapter(adapter);

        SmartTabLayout viewPagerTab = (SmartTabLayout) getActivity().findViewById(R.id.viewpagertab);
        viewPagerTab.setViewPager(viewPager);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    public static FiveFragment newInstance() {
        FiveFragment fragment1 = new FiveFragment();
        return fragment1;
    }
}
